import React, { Component } from 'react'
import { Modal, Button, Input, Form, Select } from 'antd'
import { addRoles } from '../../api/role'

export default class Add extends Component {
  state = {
    isModalVisible: false,
  }
  showModal = () => {
    this.setState({
      isModalVisible: true,
    })
  }

  handleCancel = () => {
    this.setState({
      isModalVisible: false,
    })
  }
  render() {
    let { isModalVisible } = this.state
    return (
      <>
        <Button onClick={this.showModal}>添加角色</Button>
        <Modal
          title="添加用户"
          visible={isModalVisible}
          onCancel={this.handleCancel}
          footer={null}
        >
          <Form
            name="normal_login"
            className="login-form"
            onFinish={this.onFinish}
            initialValues={{}}
          >
            <Form.Item
              label="角色名"
              name="name"
              rules={[
                {
                  required: true,
                  message: '请输入用户名!',
                },
              ]}
            >
              <Input placeholder="用户名" />
            </Form.Item>
            <Form.Item>
              <Button
                type="primary"
                htmlType="submit"
                className="login-form-button"
              >
                添加
              </Button>
            </Form.Item>
          </Form>
        </Modal>
      </>
    )
  }
  onFinish = (values) => {
    addRoles({ name: values.name }).then((res) => {
      console.log(res)
    })
    this.props.add()
    this.setState({
      isModalVisible: false,
    })
    console.log(values)
  }
}
